
<script setup lang="ts">
import { ref } from 'vue'
// import { useRouter, useRoute } from 'vue-router'
// import { useUserStore } from '@/stores/user'
// import { ElMessage } from 'element-plus'

// const router = useRouter()
// const route = useRoute()
// const userStore = useUserStore()

const loginForm = ref({
  username: 'admin',
  password: '123456'
})

const loginRules = ref({
  username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
  password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
})

const loading = ref(false)
const loginFormRef = ref()

const handleLogin = () => {
  loginFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      loading.value = true
      try {
        // const success = await userStore.login(loginForm.value)
        // if (success) {
        //   const redirect = route.query.redirect || '/'
        //   router.push(redirect as string)
        //   ElMessage.success('登录成功')
        // } else {
        //   ElMessage.error('用户名或密码错误')
        // }
      } finally {
        loading.value = false
      }
    }
  })
}
</script>
<template>
  <div class="login-container">
    <el-form
      ref="loginForm"
      :model="loginForm"
      :rules="loginRules"
      class="login-form"
    >
      <h3 class="title">管理系统</h3>
      
      <el-form-item prop="username">
        <el-input
          v-model="loginForm.username"
          placeholder="用户名"
          prefix-icon="User"
        />
      </el-form-item>
      
      <el-form-item prop="password">
        <el-input
          v-model="loginForm.password"
          type="password"
          placeholder="密码"
          prefix-icon="Lock"
          show-password
          @keyup.enter="handleLogin"
        />
      </el-form-item>
      
      <el-form-item>
        <el-button
          :loading="loading"
          type="primary"
          style="width: 100%"
          @click="handleLogin"
        >
          登录
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>


<style lang="scss" scoped>
.login-container {
  height: 100vh;
  background-color: #2d3a4b;
  display: flex;
  justify-content: center;
  align-items: center;
  
  .login-form {
    width: 400px;
    padding: 35px;
    background-color: #fff;
    border-radius: 6px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    
    .title {
      margin: 0 auto 30px;
      color: #333;
      text-align: center;
      font-size: 24px;
    }
  }
}
</style>